package see.battle.gui;

import see.battle.Const;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.MotionEvent;
import android.view.Window;
import android.view.WindowManager;

public class Result extends Activity {
  
  private ResultView _resultView;
  private int _hitNumber;
  private int _opponentHitNumber;
  private int _gameMode;
  
  public boolean onTouchEvent(MotionEvent e) {
    if (e.getActionMasked() == MotionEvent.ACTION_DOWN) {
      int w = _resultView.get_widthInPx();
      int h = _resultView.get_heightInPx();
      float x = e.getX();
      float y = e.getY();
      if ((x > Const.resultAgainButtonLeft * w) &&
          (x < (Const.resultAgainButtonLeft + 
              Const.resultAgainButtonWidth) * w) &&
              (y > Const.resultAgainButtonTop * h) &&
              (y < (Const.resultAgainButtonTop + 
                  Const.resultAgainButtonHeight) * h)) {    
        Intent intent = new Intent(this, Game.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);      
        intent.putExtra("GAME_MODE", _gameMode);
        startActivity(intent);
      } else if ((x > Const.resultBackButtonLeft * w) &&
          (x < (Const.resultBackButtonLeft + 
              Const.resultBackButtonWidth) * w) &&
              (y > Const.resultBackButtonTop * h) &&
              (y < (Const.resultBackButtonTop + 
                  Const.resultBackButtonHeight) * h)) {    
        Intent intent = new Intent(this, GameSelection.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);      
        startActivity(intent);
      }
    }
    return true;
  }
  
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
        WindowManager.LayoutParams.FLAG_FULLSCREEN);
    Bundle extras = getIntent().getExtras(); 
    if (extras != null) {
      _hitNumber = extras.getInt("HIT_NUMBER");
      _opponentHitNumber = extras.getInt("OPPONENT_HIT_NUMBER");
      _gameMode = extras.getInt("GAME_MODE");
    }
  }
  
  @Override
  public void onStart() {
    super.onStart();
    DisplayMetrics metrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(metrics);
    _resultView = new ResultView(this, metrics, _hitNumber, _opponentHitNumber);
    setContentView(_resultView);
  }

}
